package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.Favorites;
import com.sweet.fourtimeoa.pojo.entity.Roles;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.DesktopURLService;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "常用网址")
@RestController
@RequestMapping("/oa/favorites")
@CrossOrigin(origins = "*")
public class DesktopURLController {
    @Autowired
    private DesktopURLService desktopURLService;

    @Operation(summary = "常用网址_分页查询")
    @GetMapping("/queryFavorites")
    public Result queryFavorites(PageDto pageDto) {
        PageVo<Favorites> favorites = desktopURLService.queryFavorites(pageDto.getPageNum(), pageDto.getPageSize());
        return Result.success(favorites);
    }
    @Operation(summary = "常用网址_新增")
    @PostMapping("/insertFavorites")
    public Result insertFavorites(@RequestBody Favorites favorites) {
        desktopURLService.insertFavorites(favorites);
        return Result.success();
    }
    @Operation(summary = "常用网址_删除")
    @DeleteMapping("/deleteFavorites/{favoriteId}")
    public Result deleteFavorites(@PathVariable Integer favoriteId) {
        desktopURLService.deleteFavorites(favoriteId);
        return Result.success();
    }
    @Operation(summary = "常用网址_修改_获取数据")
    @GetMapping("/queryFavoritesById/{favoriteId}")
    public Result queryFavoritesById(@PathVariable Integer favoriteId) {
        return Result.success(desktopURLService.queryFavoritesById(favoriteId));
    }
    @Operation(summary = "常用网址_修改")
    @PutMapping("/updateFavorites")
    public Result updateFavorites(@RequestBody Favorites favorites) {
        desktopURLService.updateFavorites(favorites);
        return Result.success();
    }
}
